package main

import (
	"fmt"
	"math/rand"
	"sort"
)


type StuSlice []Students

type Students struct{
	Name string
	Age int
	Score float64
}

func (stus StuSlice)Len() int  {
	return len(stus)
}

func (stus StuSlice)Less(i,j int) bool{
	return stus[i].Score>  stus[j].Score
}

func (stus StuSlice)Swap(i,j int){
	stus[i],stus[j] = stus[j],stus[i]
}
func main (){
	var stus StuSlice
	for i:=0;i<5;i++{
		stu := Students{
			Name : fmt.Sprintf("stu|%d",rand.Intn(10)),
			Age : rand.Intn(40),
			Score : rand.Float64()*10,
		}

		stus = append(stus,stu)
	}

	for _,v :=range stus{
		fmt.Println(v)
	}

	fmt.Println("sort ..")
	sort.Sort(stus)
	for _,v := range stus{
		fmt.Println(v)
	}
}